package avicit.bdp.dgs.metadata.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.common.service.dto.ColumnPartitionedHistoryDTO;
import avicit.bdp.dgs.metadata.dao.MetadataTableColumnPartitionHistoryDao;
import avicit.platform6.core.exception.BusinessException;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 数据表元数据分区数据
 *
 * @author mayanj
 */
@Service
public class MetadataTableColumnPartitionHistoryService
    extends BaseService<MetadataTableColumnPartitionHistoryDao, ColumnPartitionedHistoryDTO> {

  /**
   * 根据所属表id删除
   *
   * @param tableId 表id
   */
  @Transactional(rollbackFor = Exception.class)
  public void deleteByTableId(String tableId) {
    if (StringUtils.isEmpty(tableId)) {
      throw new BusinessException("删除失败！传入的参数主键为null");
    }
    try {
      ColumnPartitionedHistoryDTO columnPartitionedHistory = new ColumnPartitionedHistoryDTO();
      columnPartitionedHistory.setTableId(tableId);
      delete(columnPartitionedHistory);
    } catch (Exception e) {
      throw new BusinessException(e.getMessage(), e);
    }
  }

  public void batchInsert(List<ColumnPartitionedHistoryDTO> list) {
    this.mapper.batchInsert(list);
  }

  public int deleteByDatasourceId(String datasourceId) {
    return this.mapper.deleteByDatasourceId(datasourceId);
  }
}
